import QtQuick 2.15
import QtPositioning 5.0  // 导入 QtPositioning 模块
Window {
    id: mainWindow
    visible: true
    width: 1280
    height: 720
    flags: Qt.Window | Qt.FramelessWindowHint
    // 自定义标题栏
    Rectangle {
        id: titleBar
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        height: 40
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#E0E0E0" }
            GradientStop { position: 1.0; color: "#007BFF" }
        }

        // 使用DragHandler来处理拖动
        DragHandler {
            id: dragHandler
            target: mainWindow.contentItem // 使用contentItem作为拖动目标
            onActiveChanged: {
                if (active) {
                    mainWindow.startSystemMove()
                }
            }
        }
        // 关闭按钮
        Rectangle {
            id: closeButton
            anchors.right: parent.right
            anchors.rightMargin: 10
            anchors.verticalCenter: parent.verticalCenter
            width: 40
            height: 40
            color: "transparent" // 设置为透明
            radius: 5
            // 鼠标悬停效果
            MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                onEntered: {
                    closeButton.color = "#FF0000" // 鼠标悬停时变为红色
                }
                onExited: {
                    closeButton.color = "transparent" // 鼠标离开时恢复透明
                }
                // 点击事件
                onClicked: {
                    Qt.quit()
                }
            }
            // 使用Canvas绘制一个简单的 "X"
            Canvas {
                anchors.centerIn: parent
                width: 24
                height: 24
                onPaint: {
                    var ctx = getContext("2d")
                    ctx.lineWidth = 3
                    ctx.strokeStyle = "#FFFFFF"
                    ctx.beginPath()
                    ctx.moveTo(8, 8)
                    ctx.lineTo(16, 16)
                    ctx.moveTo(16, 8)
                    ctx.lineTo(8, 16)
                    ctx.stroke()
                }
            }
        }
        // 标题文本
        Text {
            anchors.left: parent.left
            anchors.leftMargin: 20
            anchors.verticalCenter: parent.verticalCenter
            text: "My Chess Game V1.0"
            font.bold: true
            font.pixelSize: 16
            color: "#FFFFFF"
        }
    }
    //内容区，向下偏移40像素后填充剩余区域
    Rectangle {
        id: contentArea
        anchors.top: titleBar.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        color: "#F0F0F0"
    }
}
